package com.lucien.admin.controller.system;

import com.lucien.common.result.GlobalResult;
import com.lucien.system.domain.SysApply;
import com.lucien.system.service.SysApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "好友申请接口")
@RequestMapping("/apply")
public class SysApplyController {

    @Autowired
    private SysApplyService applyService;

    @PostMapping("/sendapply/{userId}")
    @ApiOperation(value = "发送好友申请")
    public GlobalResult sendApply(@PathVariable("userId") int userId){
        int result = applyService.sendApply(userId);
        if (result == 1){
            return GlobalResult.success("发送成功", result);
        }else {
            return GlobalResult.error("发送失败请稍后再尝试", result);
        }
    }

    @GetMapping("/agree/{id}")
    @ApiOperation(value = "同意申请")
    public GlobalResult agree(@PathVariable("id") Long id){
        int result = applyService.agreeApply(id);
        return GlobalResult.success("同意申请", result);
    }

    @GetMapping("/disagree/{id}")
    @ApiOperation(value = "拒绝申请")
    public GlobalResult disAgree(@PathVariable("id") Long id){
        int result = applyService.disAgree(id);
        return GlobalResult.success("拒绝申请", result);
    }

    @GetMapping("/listapply")
    @ApiOperation(value = "查询申请列表")
    public GlobalResult listApply(){
        List<SysApply> result = applyService.listApply();
        return GlobalResult.success("查询成功", result);
    }

    @GetMapping("/delapply/{id}")
    @ApiOperation(value = "删除申请记录")
    public GlobalResult delApply(@PathVariable("id") Long id){
        int result = applyService.delApply(id);
        return GlobalResult.success("查询成功", result);
    }
}
